﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;

namespace GGGK.Film.Comm
{
    public class ConfigurationHelper
    {
        /// <summary>
        /// 配置项集合
        /// </summary>
        private static IConfiguration? configuration;
        
        /// <summary>
        /// 获取配置文件集合
        /// </summary>
        /// <returns></returns>
        /// 用例：ConfigurationHelper.GetConfiguration().GetSection("配置项的key")
        public static IConfiguration GetConfiguration()
        {
            if(configuration == null)
            {
                configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).Add(new JsonConfigurationSource()
                {
                    Path = "appsettings.json",
                    ReloadOnChange = true
                }).Build();
            }
            return configuration;
        }
    }
}
